package com.qiyue.admin.auth.utils.jwt.utils;


import com.qiyue.admin.auth.configuration.JwtKeyConfiguration;
import com.qiyue.admin.auth.utils.model.IJWTInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * Created with Intellij IDEA.
 * User : Yebinghuan
 * Created on 2018/2/10.
 * Description :
 */
@Component
public class JwtTokenUtil {

    @Value("${jwt.expire}")
    private int expire;
    @Autowired
    private JwtKeyConfiguration jwtKeyConfiguration;

//    @Autowired
//    private RedisTemplate<String, Object> redisTemplate;

    public String generateToken(IJWTInfo jwtInfo) throws Exception {

        return JWTHelper.generateToken(jwtInfo, jwtKeyConfiguration.getUserPriKey(),expire);
    }

    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, jwtKeyConfiguration.getUserPubKey());
    }
}
